package com.nondo.dean.platform.controller.api.inner;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.platform.domain.Slide;
import com.nondo.dean.platform.model.SlideBean;
import com.nondo.dean.platform.service.SlideService;

/**
 * 幻灯片管理内部接口
 * @author zlj
 * @date 2018年4月9日
 */
@RestController("apiInnerSlide")
@RequestMapping("/{v}/inner/slide")
public class SlideController {
    
    @Autowired
    SlideService slideService;
    
    /**
     * 查看幻灯片详情
     * @param request
     * @param response
     * @param id
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/info/{id}")
    public View<SlideBean> info(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Integer id) {
        View<SlideBean> view = new View<SlideBean>(20000, "获取数据成功");
        
        SlideBean slideBean = new SlideBean();
        if (id != null) {
            Slide slide = slideService.selectSlide(id);
            slideBean = slideService.getSlideBean(slide);
        } 

        view.setData(slideBean);
        return view;
    }
    
    /**
     * 获取经销商采购页面幻灯片列表
     * @param request
     * @param response
     * @param query
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/list/{position}")
    public View<List<SlideBean>> list(HttpServletRequest request, HttpServletResponse response, @PathVariable(
        name = "position") int position) {
        View<List<SlideBean>> view = new View<List<SlideBean>>(20000, "获取列表成功");

        List<Slide> slideList = slideService.getSlideList(position);
        
        List<SlideBean> slideBeanList = new ArrayList<SlideBean>();
        
        for (Slide slide : slideList) {
            SlideBean slideBean = slideService.getSlideBean(slide);
            slideBeanList.add(slideBean);
        }
        
        view.setData(slideBeanList);
        
        return view;
    }
}